﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class Ballnosedendmillsolid
    {
        public static void _Ballnosedendmillsolid(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double scale = 3; //放大系数

            double dc = 8;
            double dconms = 8;
            double oal = 63;
            double apmx = 25.75;
            double fha = 30;
            double ls = 18.2;
            double dn = 7.3;
            double lpr = 48.87;



            //坐标
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + oal + 4, v1.Y);
            Vector2 v3 = new Vector2(v1.X + 2, v1.Y);
            Vector2 v4 = new Vector2(v3.X, v3.Y + dconms / 2 - 0.8);
            Vector2 v5 = new Vector2(v4.X + 0.6, v3.Y + dconms / 2);
            Vector2 v6 = new Vector2(v3.X + ls, v5.Y);
            Vector2 v7 = new Vector2(v6.X + oal / 56.247, v3.Y + dn / 2);
            Vector2 v17 = new Vector2(v3.X + oal - apmx, v3.Y - dconms / 2.5);
            Vector2 v16 = new Vector2(v17.X - oal / 33.5, v3.Y - dn / 2);
            Vector2 v8 = new Vector2(v16.X, v7.Y);
            Vector2 v9 = new Vector2(v8.X + oal / 45.109, v8.Y);
            Vector2 v10 = new Vector2(v4.X, v4.Y * -1);
            Vector2 v11 = new Vector2(v5.X, v5.Y * -1);
            Vector2 v13 = new Vector2(v6.X, v6.Y * -1);
            Vector2 v14 = new Vector2(v7.X, v7.Y * -1);
            Vector2 v15 = new Vector2(v3.X + oal - lpr, v3.Y);
            Vector2 v12 = new Vector2(v15.X, v15.Y - dconms / 2 - 2);
            Vector2 v18 = new Vector2(v15.X, v12.Y * -1);
            Vector2 v19 = new Vector2(v8.X, v8.Y - dc / 28.923);
            Vector2 v20 = new Vector2(v9.X - apmx / 9.264, v9.Y - dc / 10.507);
            Vector2 v21 = new Vector2(v9.X - apmx / 7.478, v9.Y - dc / 2.212);
            Vector2 v22 = new Vector2(v16.X, v16.Y + dc / 3.125);
            Vector2 v23 = new Vector2(v16.X + apmx / 5.949, v16.Y + dc / 5.489);
            Vector2 v24 = new Vector2(v17.X + apmx / 11.785, v17.Y - dc / 35.81);
            Vector2 v25 = new Vector2(v23.X + apmx / 2.415, v23.Y - dc / 7.231);
            Vector2 v26 = new Vector2(v9.X + apmx / 10.344, v9.Y - dc / 31.333);
            Vector2 v27 = new Vector2(v26.X + apmx / 3.205, v26.Y - dc / 3.465);
            Vector2 v28 = new Vector2(v27.X + apmx / 5.987, v27.Y - dc / 3.76);
            Vector2 v29 = new Vector2(v28.X + apmx / 6.481, v28.Y - dc / 5.529);
            Vector2 v30 = new Vector2(v9.X + apmx / 5.729, v9.Y - dc / 9.766);
            Vector2 v31 = new Vector2(v30.X + apmx / 7.923, v30.Y - dc / 6.655);
            Vector2 v32 = new Vector2(v31.X + apmx / 3.644, v31.Y - dc / 2.118);
            Vector2 v34 = new Vector2(v32.X + apmx /6.83, v32.Y - dc / 7.92);
            Vector2 v57 = new Vector2(v3.X + oal, v3.Y);
            Vector2 v33 = new Vector2(v57.X - apmx / 4.99, v57.Y - dc / 2.089);
            Vector2 v53 = new Vector2(v57.X - dc / 2, v57.Y + dc / 2);
            Vector2 v35 = new Vector2(v57.X - apmx / 13.342, v57.Y - dc / 2.346);
            Vector2 v45 = new Vector2(v29.X + apmx / 9.31, v29.Y - dc / 14.189);
            Vector2 v36 = new Vector2(v26.X + apmx / 3.936, v26.Y + dc / 14.189);
            Vector2 v37 = new Vector2(v36.X + apmx / 5.729, v36.Y - dc / 25.067);
            Vector2 v38 = new Vector2(v37.X + apmx / 6.82, v37.Y - dc / 11.75);
            Vector2 v39 = new Vector2(v38.X + apmx / 6.355, v38.Y - dc / 5.45);
            Vector2 v40 = new Vector2(v39.X + apmx / 15.517, v39.Y - dc / 10.444);
            Vector2 v41 = new Vector2(v40.X + apmx / 8.131, v40.Y - dc / 6.483);
            Vector2 v42 = new Vector2(v39.X + apmx / 23.57, v39.Y - dc / 16);
            Vector2 v43 = new Vector2(v42.X + apmx / 27.382, v42.Y - dc / 2.961);
            Vector2 v44 = new Vector2(v57.X - apmx / 40.873, v57.Y - dc / 3.721);
            Vector2 v46 = new Vector2(v36.X + apmx / 6.085, v36.Y);
            Vector2 v47 = new Vector2(v46.X + apmx / 4.175, v46.Y - dc / 6.065);
            Vector2 v48 = new Vector2(v47.X + apmx / 4.508, v47.Y - dc / 4.398);
            Vector2 v49 = new Vector2(v57.X - apmx / 232.75, v57.Y + dc/10.162);
            Vector2 v50 = new Vector2(v53.X - apmx / 6.421, v53.Y - dc / 23.5);
            Vector2 v51 = new Vector2(v50.X + apmx / 5.144, v50.Y - dc / 7.673);
            Vector2 v52 = new Vector2(v57.X - apmx / 71.615, v57.Y + dc / 5.612);
            Vector2 v54 = new Vector2(v47.X + apmx / 18.808, v47.Y - dc / 18.341);
            Vector2 v55 = new Vector2(v50.X + apmx / 6.045, v50.Y - dc / 9.06);
            Vector2 v56 = new Vector2(v53.X + apmx / 28.646, v53.Y - dc / 94);
            Vector2 v58 = new Vector2(v57.X - dc / 2, v57.Y - dc / 2);
            Vector2 v59 = new Vector2(v57.X, v58.Y);





            //作图
            Line line1 = new Line(v1, v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.DashDot;
            line1.LinetypeScale = 3;
            dxf.AddEntity(line1);

            Line line2 = new Line(v18, v12);
            line2.Layer = centre;
            line2.Linetype = Linetype.DashDot;
            line2.LinetypeScale = 3;
            dxf.AddEntity(line2);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v9));
            line3.Vertexes.Add(new LwPolylineVertex(v7));
            line3.Vertexes.Add(new LwPolylineVertex(v6));
            line3.Vertexes.Add(new LwPolylineVertex(v5));
            line3.Vertexes.Add(new LwPolylineVertex(v4));
            line3.Vertexes.Add(new LwPolylineVertex(v10));
            line3.Vertexes.Add(new LwPolylineVertex(v11));
            line3.Vertexes.Add(new LwPolylineVertex(v13));
            line3.Vertexes.Add(new LwPolylineVertex(v14));
            line3.Vertexes.Add(new LwPolylineVertex(v16));
            line3.Vertexes.Add(new LwPolylineVertex(v17));
            fun.PolyFill(dxf, line3, 0.1, contour);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v5));
            line4.Vertexes.Add(new LwPolylineVertex(v11));
            line4.Vertexes.Add(new LwPolylineVertex(v13));
            line4.Vertexes.Add(new LwPolylineVertex(v6));   
            line4.Vertexes.Add(new LwPolylineVertex(v7));
            line4.Vertexes.Add(new LwPolylineVertex(v14));
            fun.PolyFill(dxf, line4, 0.1, contour);

            Arc c1 = fun.DrawArc3(v27, v26, v9);
            fun.drawBArc(dxf, c1, 0.1, contour);

            Arc c2 = fun.DrawArc3(v9, v19, v20);
            fun.drawBArc(dxf, c2, 0.1, contour);

            Arc c3 = fun.DrawArc3(v21, v22, v23);
            fun.drawBArc(dxf, c3, 0.1, contour);

            Arc c4 = fun.DrawArc3(v23, v25, v34);
            fun.drawBArc(dxf, c4, 0.1, contour);

            LwPolyline line5 = new LwPolyline();
            line5.Vertexes.Add(new LwPolylineVertex(v17));
            line5.Vertexes.Add(new LwPolylineVertex(v24));
            line5.Vertexes.Add(new LwPolylineVertex(v16));
            line5.Vertexes.Add(new LwPolylineVertex(v22));
            fun.PolyFill(dxf, line5, 0.1, contour);

            LwPolyline line6 = new LwPolyline();
            line6.Vertexes.Add(new LwPolylineVertex(v8));
            line6.Vertexes.Add(new LwPolylineVertex(v19));
            fun.PolyFill(dxf, line6, 0.1, contour);

            LwPolyline line7 = new LwPolyline();
            line7.Vertexes.Add(new LwPolylineVertex(v33));
            line7.Vertexes.Add(new LwPolylineVertex(v32));
            line7.Vertexes.Add(new LwPolylineVertex(v31));
            line7.Vertexes.Add(new LwPolylineVertex(v30));
            line7.Vertexes.Add(new LwPolylineVertex(v9));
            line7.Vertexes.Add(new LwPolylineVertex(v32));
            line7.Vertexes[4].Bulge = Math.Tan(38 * pi / 180 / 4);
            fun.PolyFill(dxf, line7, 0.1, contour);

            LwPolyline line8 = new LwPolyline();
            line8.Vertexes.Add(new LwPolylineVertex(v20));
            line8.Vertexes.Add(new LwPolylineVertex(v21));
            line8.Vertexes[0].Bulge = Math.Tan(110 * pi / 180 / 4);
            fun.PolyFill(dxf, line8, 0.1, contour);

            LwPolyline line9 = new LwPolyline();
            line9.Vertexes.Add(new LwPolylineVertex(v24));
            line9.Vertexes.Add(new LwPolylineVertex(v25));
            line9.Vertexes[0].Bulge = Math.Tan(18 * pi / 180 / 4);
            fun.PolyFill(dxf, line9, 0.1, contour);

            Arc c5 = fun.DrawArc3(v33, v35, v44);
            fun.drawBArc(dxf, c5, 0.1, contour);

            Arc c6 = fun.DrawArc3(v46, v36, v26);
            fun.drawBArc(dxf, c6, 0.1, contour);

            Arc c7 = fun.DrawArc3(v40, v43, v44);
            fun.drawBArc(dxf, c7, 0.1, contour);

            Arc c8 = fun.DrawArc3(v44, v41, v57);
            fun.drawBArc(dxf, c8, 0.1, contour);

            Arc c9 = fun.DrawArc3(v57, v49, v52);
            fun.drawBArc(dxf, c9, 0.1, contour);

            Arc c10 = fun.DrawArc3(v52, v56, v53);
            fun.drawBArc(dxf, c10, 0.1, contour);

            LwPolyline line10 = new LwPolyline();
            line10.Vertexes.Add(new LwPolylineVertex(v27));
            line10.Vertexes.Add(new LwPolylineVertex(v28));
            line10.Vertexes.Add(new LwPolylineVertex(v29));
            line10.Vertexes.Add(new LwPolylineVertex(v45));
            line10.Vertexes.Add(new LwPolylineVertex(v35));
            line10.Vertexes.Add(new LwPolylineVertex(v45));
            line10.Vertexes.Add(new LwPolylineVertex(v43));
            fun.PolyFill(dxf, line10, 0.1, contour);

            LwPolyline line11 = new LwPolyline();
            line11.Vertexes.Add(new LwPolylineVertex(v36));
            line11.Vertexes.Add(new LwPolylineVertex(v37));
            line11.Vertexes.Add(new LwPolylineVertex(v38));
            line11.Vertexes.Add(new LwPolylineVertex(v39));
            line11.Vertexes.Add(new LwPolylineVertex(v42));
            line11.Vertexes.Add(new LwPolylineVertex(v40));
            line11.Vertexes.Add(new LwPolylineVertex(v57));
            line11.Vertexes.Add(new LwPolylineVertex(v40));
            line11.Vertexes.Add(new LwPolylineVertex(v41));
            fun.PolyFill(dxf, line11, 0.1, contour);

            LwPolyline line12 = new LwPolyline();
            line12.Vertexes.Add(new LwPolylineVertex(v46));
            line12.Vertexes.Add(new LwPolylineVertex(v50));
            line12.Vertexes.Add(new LwPolylineVertex(v55));
            line12.Vertexes.Add(new LwPolylineVertex(v51));
            line12.Vertexes.Add(new LwPolylineVertex(v52));
            fun.PolyFill(dxf, line12, 0.1, contour);

            LwPolyline line13 = new LwPolyline();
            line13.Vertexes.Add(new LwPolylineVertex(v53));
            line13.Vertexes.Add(new LwPolylineVertex(v50));
            fun.PolyFill(dxf, line13, 0.1, contour);

            LwPolyline line14 = new LwPolyline();
            line14.Vertexes.Add(new LwPolylineVertex(v56));
            line14.Vertexes.Add(new LwPolylineVertex(v55));
            line14.Vertexes.Add(new LwPolylineVertex(v54));
            line14.Vertexes[0].Bulge = Math.Tan(72 * pi / 180 / 4);
            line14.Vertexes[1].Bulge = Math.Tan(71 * pi / 180 / 4);
            fun.PolyFill(dxf, line14, 0.1, contour);

            LwPolyline line15 = new LwPolyline();
            line15.Vertexes.Add(new LwPolylineVertex(v46));
            line15.Vertexes.Add(new LwPolylineVertex(v47));
            line15.Vertexes.Add(new LwPolylineVertex(v54));
            line15.Vertexes.Add(new LwPolylineVertex(v48));
            line15.Vertexes.Add(new LwPolylineVertex(v49));
            fun.PolyFill(dxf, line15, 0.1, contour);


            fun.drawcircle(dxf, v59, 1, 0.1, dimensioning);


            //坐标系
            fun.Axis(dxf, v3, -90, 180, "", "", "PCS", 0.5, 2, 0);

            fun.Axis(dxf, v15, -90, 180, "", "", "MCS", 0.5, 2, 0);

            fun.Axis(dxf, v57, -90, 180, "", "", "CIP", 0.5, 2, 0);



            //标注

            double height = 2;
            double arrowsize = 2;
            double exline = 2;



            fun.dimrot1(dxf, v57, v4, 0, oal / 2, 1, height, arrowsize, exline, "OAL,LF", "", "");

            fun.dimrot1(dxf, v57, v18, 0, oal / 3, 1, height, arrowsize, exline, "LPR,LTA", "", "");

            fun.dimrot1(dxf, v5, v11, 90, dconms / 2, 1, height, arrowsize, exline, "DCONMS", "", "");

            fun.dimrot1(dxf, v7, v14, -90, dconms, 1, height, arrowsize, exline, "DN", "", "");

            fun.dimrot1(dxf, v10, v13, 180, dconms, 1, height, arrowsize, exline, "LS", "", "");

            fun.dimrot1(dxf, v14, v57, 180, oal / 3, 1, height, arrowsize, exline, "LU", "", "");

            fun.dimrot1(dxf, v17, v57, 180, dconms, 1, height, arrowsize, exline, "APMX", "", "");

            fun.dimrot1(dxf, v56, v58, -90, dconms, 1, height, arrowsize, exline, "DC,DCX", "", "");

            fun.jdbz2(dxf, new Line(v57, fun.Polar(v57, 90 * pi / 180, 0.1)), new Line(v53, fun.Polar(v53, -175 * pi / 180, 0.1)), apmx / 2, height, arrowsize, exline, "KAPR", "", "");

            fun.jdbz2(dxf, new Line(v31, fun.Polar(v31, 150 * pi / 180, 0.1)), new Line(v57, fun.Polar(v57, 180 * pi / 180, 0.1)), apmx / 2, height, arrowsize, exline, "FHA", "", "");

            fun.jt(dxf, new Vector2(v57.X + oal / 4.565, v57.Y + dc / 0.287), -90, 9, height, "FDP");

            fun.jt(dxf, v56, 45, 9, height, "RE");

            fun.jt(dxf, new Vector2(v15.X - ls / 10.605, v5.Y), 118, 9, height, "CCMS");

            fun.text1(dxf, new Vector2(v59.X  + oal / 52.977, v59.Y - dc / 1.765), 90, "CRP");






            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}
